package com.itgone.manager.controller;

import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.Map;

/**
 * @Author: earlman
 * @Description:
 * @Date:Create：in 2021-06-06 17:34
 */
@RestController
@RequestMapping("/redis")
public class RedisController {

    @Resource
    private RedisTemplate<String, Object> redisTemplate;

    @GetMapping("/get/{key}")
    public Object get(@PathVariable String key) {
        Object value = redisTemplate.opsForValue().get(key);
        System.out.println(value);
        return value;
    }

    @GetMapping("/set/{key}/{value}")
    public Object set(@PathVariable String key, @PathVariable String value) {
        redisTemplate.opsForValue().set(key, value);
        System.out.println(key + "  :  " + value);
        return value;
    }

    @GetMapping("/hmget/{key}")
    public Map<Object, Object> hmget(@PathVariable String key) {
        return redisTemplate.opsForHash().entries(key);
    }
}
